home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / prodpack.zip / DB4PPSRC.EXE / _FFILE.PRG < prev    next >
Text File  |  1993-05-04  |  3KB  |  125 lines

  1. *' $Header:   E:/test/sysproc/doc/_ffile.prv   1.2   12 Aug 1992 16:55:56   Bill Ramos  $
  2. FUNCTION _FFile
  3. PARAMETER pc_file
  4. *--------------------------------------------------------------------------
  5. * NAME
  6. *   FFILE - Determine if a file exists in the dBASE
  7. *           path.
  8. *
  9. * SYNOPSIS
  10. *   FFILE( pc_file )
  11. *
  12. * DESCRIPTION
  13. *   FFILE() searches the dBASE path for the given file
  14. *   pc_file and returns the path with a trailing "\"
  15. *   if found.  If the file is not found, FFILE() will
  16. *   return a null string.
  17. *
  18. *   FFILE() will search the current directory first,
  19. *   then process other directories in the order of the
  20. *   SET PATH list.
  21. *
  22. *   If there is no dBASE PATH setting, FFILE() will
  23. *   look only in the current directory.
  24. *
  25. *   The file name may have trailing blanks, but not
  26. *   leading blanks.
  27. *
  28. * PARAMETER
  29. *   pc_file - the file to search for.
  30. *
  31. * EXAMPLE
  32. *
  33. *    SET PATH TO C:\DBASE,C:\CCBOOSTR\SAMPLES
  34. *    ? FFile( "CONFIG.DB" )
  35. *    * Would return: "C:\DBASE\"
  36. *    * if CONFIG.DB is in the C:\DBASE directory
  37. *
  38. * LIMITATIONS
  39. *   The file name passed to FFILE() must not include a
  40. *   path name.
  41. *
  42. *   Since FFILE() uses the dBASE FILE() command, in
  43. *   some rare situations (when too many files have
  44. *   been opened) FFILE() may return "" even though the
  45. *   file really is in the search path.  Modifying the
  46. *   "FILES=" statement in the DOS CONFIG.SYS file will
  47. *   normally correct this.
  48. *
  49. * VERSION
  50. *   dBASE IV 1.1
  51. *
  52. * SEE ALSO:
  53. *   FILE, SET("PATH")
  54. *
  55. *--------------------------------------------------------------------------
  56.  
  57.   PRIVATE lc_curdir, lc_path, lc_return, lc_spath, ln_delim, lc_slash
  58.  
  59.   IF LEFT( OS(), 3 ) = "DOS"
  60.     lc_slash = "\"
  61.   ELSE
  62.     lc_slash = "/"
  63.   ENDIF
  64.  
  65.   lc_path   = SET( "PATH" )
  66.   lc_curdir = SET( "DIRECTORY" )
  67.   lc_return = ""
  68.  
  69.   *-- If no path, then check the current directory
  70.   IF IsBlank( lc_path )
  71.  
  72.     IF FILE( pc_file )
  73.       lc_return = lc_curdir + lc_slash
  74.     ENDIF
  75.  
  76.   ELSE
  77.     *-- Check the current directory first
  78.     IF FILE( lc_curdir + lc_slash + pc_file )
  79.       lc_return = lc_curdir + lc_slash
  80.     ELSE
  81.       ln_delim = MAX( AT( ",", lc_path ), AT( ";", lc_path ) )
  82.  
  83.       DO WHILE ln_delim <> 0
  84.         lc_spath = LEFT( lc_path, ln_delim - 1 )
  85.  
  86.         IF RIGHT( TRIM( lc_spath ), 1 ) <> lc_slash
  87.           lc_spath = TRIM( lc_spath ) + lc_slash
  88.         ENDIF
  89.  
  90.         IF FILE( lc_spath + pc_file )
  91.           lc_return = lc_spath
  92.           EXIT
  93.         ENDIF
  94.  
  95.         lc_path = SUBSTR( lc_path, ln_delim + 1 )
  96.         ln_delim = MAX( AT( ",", lc_path ), AT( ";", lc_path ) )
  97.  
  98.         IF ln_delim = 0
  99.           lc_spath = lc_path
  100.  
  101.           IF RIGHT( TRIM( lc_spath ), 1 ) <> lc_slash
  102.             lc_spath = TRIM( lc_spath ) + lc_slash
  103.           ENDIF
  104.  
  105.           IF FILE( lc_spath + pc_file )
  106.             lc_return = lc_spath
  107.             EXIT
  108.           ENDIF
  109.  
  110.         ENDIF
  111.  
  112.       ENDDO
  113.  
  114.     ENDIF
  115.  
  116.   ENDIF
  117.  
  118. RETURN( UPPER( lc_return ) )
  119. *-- EOF: FFile( pc_file )
  120. *'-------------------------------------------------------------------------
  121. *' $Log:   E:/test/sysproc/doc/_ffile.prv  $
  122. *'-------------------------------------------------------------------------
  123.  
  124.  
  125.